<!DOCTYPE html> 
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1">
        <script src="../../boot.js"></script>
        <script src="../../lib/jquery/jquery-1.8.0.js"></script>
    </head>
    <body style="padding:10px;">
    	<input type="file" name="file" class="file" onChange="_start();">
        <input type="button" value="取消" onClick="cancel();">
    	<div id="response"></div>
      <!--  function(data,s,f){
						console.log( data );
						setTimeout(function(){
							s('----')	
						},data.C*1000);
					},//-->
       <script type="text/javascript">
	   	var ajax;
		var console = console || { log:$.noop};
		
		function _start(){
			ajax = Nex.Create('ajax',{
					url : 'text.php?t='+$.now(),
					//sendType : 'file',
					fileFields : '.file',
					data : {
						C : 4	
					},	
					timeout : 4000,
					dataFilter : function(d,t){
						console.log(d,t);	
						return d+'nobooo';
					},
					onBeforeSend : function(){
						$('#response').append('loading...<br>');	
						console.log( arguments );	
					},
					onSuccess : function(d){
						$('#response').append(d);
						console.log( arguments );		
					},
					onError : function(d){
						$('#response').append(' error ');	
						console.log( 'error',arguments );	
					},
					onAbort : function(xhr, d){
						$('#response').append(d);	
						console.log( 'abort',arguments );	
					},
					onComplete : function(d){
						$('#response').append(' comolete ');	
						console.log( arguments );	
					}
				});	
		}
		function cancel(){
			ajax.abort();	
		}
		var def;
		var aj;
		var def2 = $.Deferred();
		def2.resolveWith({a:1},[1,2,3]);
			require(['Nex/Ajax'] ,function(ajax){
				
				abort = Nex.Create('ajax',{
					url:'text.php?C=20',
					timeout : 5000,
					onAbort:function(){console.log('...onAbort...')},
					onError : function(){console.log('timeout')}
				});
				
				custom = Nex.Create('ajax',{
					url: function(d,s,f){
						return $.ajax({
							url : 'text.php?C=40',
							error : f
						});
					},
					data : {
						a : 1,
						b : 2	
					},
					timeout : 6000,
					onAbort:function(){console.log('...onAbort...')},
					onError : function(){console.log('timeout')}
				});
				
				//start();
				//_start();
				def = Nex.when(
					Nex.Create('ajax',{url:'text.php?C=1',onSuccess:function(){console.log(1)}}),
					Nex.Create('ajax',{url:'text.php?C=2',onSuccess:function(){console.log(2)}}),
					Nex.Create('ajax',{url:'text.php?C=3',onSuccess:function(){console.log(3)}}),
					Nex.Create('ajax',{url:'text.php?C=4',onSuccess:function(){console.log(4)}})
				)
				.fail(function(){
					console.log('fail')	
				}).done(function(){
					console.log('done');
					Nex.Create('ajax',{url:'text.php?C=1',onSuccess:function(){console.log(1)}})
					.then(function(){
						return Nex.Create('ajax',{url:'text.php?C=1',onSuccess:function(){console.log(2)}});
					})
					.then(function(){
						return Nex.Create('ajax',{url:'text.php?C=1',onSuccess:function(){console.log(3)}});
					})
					.then(function(){
						return Nex.Create('ajax',{url:'text.php?C=1',onSuccess:function(){console.log(4)}});
					});		
				});
			});
		</script> 
        
    </body>
</html>
